package cn.gameo2o.controller.hdgl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import cn.gameo2o.pojo.O2o_play;
import cn.gameo2o.service.hdgl.HuoDongGuanLiService;
import cn.gameo2o.util.PageParam;

/**
 * @author 孙祺然
 * 活动管理controller
 */
@Controller
@RequestMapping("/hdgl")
public class HuoDongGuanLiController {
	
    @Resource
    private HuoDongGuanLiService hdglService;

	@RequestMapping("/findHD")
    public PageParam findHD(@RequestParam(required = false) String playName,@RequestParam(required = false) String playTime,@RequestParam(required = false) String userId,@RequestParam() Integer limit,@RequestParam() Integer offset){
          Map param=new HashMap();
          if(playName!=null) {
              param.put("playName", playName);
          }
          if(playTime!=null&&!"".equals(playTime)){
              param.put("playTime",playTime);
          }
          if(userId!=null&&!"".equals(userId)){
              param.put("userId",userId);
          }

          PageParam page=new PageParam();
          page.setPageSize(limit);
          page.setFirst(offset);
          hdglService.findHD(param,page);
          return page;
    }
    @RequestMapping("/addHD")
    public String addHD(@ModelAttribute O2o_play p){
    	hdglService.addHD(p);
        return "添加成功！";
    }
    @RequestMapping("/deleteHD")
    public String deleteHD(@RequestParam(value = "sid",required = false) String id){
    	hdglService.deleteHD(Integer.parseInt(id));
        return "index";
    }

    @RequestMapping("/findById")
    public O2o_play findById(@RequestParam(value="sid",required=false) String id ){
    	O2o_play p = hdglService.findById(Integer.parseInt(id));
        return p;
    }

    @RequestMapping("/updateHD")
    public String updateHD(@ModelAttribute O2o_play p){
    	hdglService.updateHD(p);
        return "更新成功！";
    }
}
